import { fileURLToPath } from "url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import tailwindcss from "@tailwindcss/vite";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

import pkg from "./package.json";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 6088,
    host: "0.0.0.0",
    proxy: {
      "/api": {
        target: "http://192.168.199.114:8098",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    tailwindcss(),
    AutoImport({
      imports: ["vue", "vue-router"],
      dts: "src/types/auto-imports.d.ts", // 生成类型声明文件
      dirs: ["src/hooks/useReactive.ts"],
      eslintrc: {
        enabled: true,
        filepath: ".eslintrc-auto-import.json",
      },
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  define: {
    __APP_ENV__: {
      __APP_VERSION__: pkg.version,
      __APP_NAME__: pkg.name,
    },
  },
});
